package com.example.bausip;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;

public class StudentCourseActivity extends Activity implements
		OnItemSelectedListener {

	ArrayList<Instructor> intsructors = new ArrayList<Instructor>();
	ArrayList<Student> assistants = new ArrayList<Student>();
	TextView intsructorsSP, assistantsSP;
	// ExpandableListAdapter listAdapter;
	// ExpandableListView expListView;
	List<String> listDataHeader;
	HashMap<String, List<String>> listDataChild;
	int course_id = 0;
	TextView id_txt, name_txt, desc_txt, credits_txt;
	Course mycourse;
	GlobalM glob = new GlobalM();
	int instructor_id;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_student_course);
		intsructorsSP = (TextView) findViewById(R.id.instructorSP);
		assistantsSP = (TextView) findViewById(R.id.assistantSP);
		Bundle extras = getIntent().getExtras();
		course_id = extras.getInt("course_id");
		Log.d("ray", "getting id :" + course_id);
		id_txt = (TextView) findViewById(R.id.courseId);
		id_txt.setFocusable(false);
		name_txt = (TextView) findViewById(R.id.courseName);
		desc_txt = (TextView) findViewById(R.id.addDesc);
		credits_txt = (TextView) findViewById(R.id.credits);

		getCourse(course_id);
	}

	public void getCourse(int course_id) {
		String serverURL = new myURL("read_courses.php?id=" + course_id, true)
				.getURL();
		RZHelper p = new RZHelper(serverURL, this, "setCourses", true);
		p.get();
	}

	public void setCourses(String s, String error) {
		Log.d("ray", "Course info " + s);
		mycourse = new APIManager().getCourses(s).get(0);
		id_txt.setText(mycourse.getId() + "");
		name_txt.setText(mycourse.getCourse_name());
		desc_txt.setText(mycourse.getCourse_description());
		credits_txt.setText(mycourse.getId() + "");
		intsructorsSP.setText(mycourse.getInstructor());
		instructor_id = mycourse.getInstructor_id();

	}

	public void goToStudents(View v) {
		Intent i = new Intent(getBaseContext(), StudentsActivity.class);
		i.putExtra("course_id", course_id);
		startActivity(i);
	}

	public void goToQuestions(View v) {
		Intent i = new Intent(getBaseContext(), QuestionsActivity.class);
		switch (v.getId()) {
		case R.id.mquestions:
			i.putExtra("type", "my");
			break;
		default:
			i.putExtra("type", "public");
			break;

		}
		i.putExtra("course_id", course_id);
		startActivity(i);
	}

	public void goToTasks(View v) {
		Intent i = new Intent(getBaseContext(), TasksActivity.class);
		i.putExtra("course_id", course_id);
		startActivity(i);
	}

	public void addTask(View v) {
		Intent i = new Intent(getBaseContext(), AddTaskActivity.class);
		i.putExtra("course_id", course_id);
		startActivity(i);
	}

	public void goToSchedule(View v) {
		Intent i = new Intent(getBaseContext(), CourseScheduleActivity.class);
		i.putExtra("course_id", course_id);
		startActivity(i);
	}
	public void goToOfficeHours(View v) {
		Intent i = new Intent(getBaseContext(), OfficeHoursActivity.class);
		i.putExtra("instructor_id", instructor_id);
		startActivity(i);
	}
	public void addQuestion(View v)
	{
		Intent i = new Intent(getBaseContext(), AddQuestionActivity.class);
		i.putExtra("course_id", course_id);
		startActivity(i);
	}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.course, menu);
		return true;
	}

	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		Log.d("ray", "ray nothing");
	}

	@Override
	public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
			long arg3) {

		Log.d("ray", "selected inst: " + position);
	}

}
